﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AutoBackupDatabase.DBConection;
using System.Data;
using System.Data.SqlClient;
using AutoBackupDatabase.ENT;


namespace AutoBackupDatabase.DAL
{
    public class AREADAL
    {
        private DbConnection conn;
        public AREADAL()
        {
            conn = new DbConnection();
        }
       

        public List<AREAENT> GetAllareaData()
        {
            string query = string.Format("exec GET_AREA_ALL ");
            DataTable ds = conn.executeGetQuery(query);
            List<AREAENT> List = new List<AREAENT>();
            foreach (DataRow item in ds.Rows)
            {
                AREAENT area = new AREAENT();
                area.AREAID = item["AREAID"].ToString();
                area.AREANAME = item["AREANAME"].ToString();
                List.Add(area);
            }
           
            return List;
        }
          public bool INSERTAREA(AREAENT ent)
          {
              string query = "exec  INSERTAREA @AREAID,@AREANAME";
              SqlParameter[] sqlParameters = new SqlParameter[2];
              sqlParameters[0] = new SqlParameter("@AREAID", SqlDbType.VarChar);
              sqlParameters[0].Value = Convert.ToString(ent.AREAID);
              sqlParameters[1] = new SqlParameter("@AREANAME", SqlDbType.NVarChar);
              sqlParameters[1].Value = Convert.ToString(ent.AREANAME);
              return conn.executeInsertQuery(query, sqlParameters);
          }
          public bool UPDATEAREABYAREAID(AREAENT ent)
          {
              string query = "exec  UPDATEAREABYAREAID @AREAID,@AREANAME";
              SqlParameter[] sqlParameters = new SqlParameter[2];
              sqlParameters[0] = new SqlParameter("@AREAID", SqlDbType.VarChar);
              sqlParameters[0].Value = Convert.ToString(ent.AREAID);
              sqlParameters[1] = new SqlParameter("@AREANAME", SqlDbType.NVarChar);
              sqlParameters[1].Value = Convert.ToString(ent.AREANAME);
              return conn.executeUpdateQuery(query, sqlParameters);
          }
          public bool DELTELEAREABYAREAID(AREAENT ent)
          {
              string query = "exec  DELTELEAREABYAREAID @AREAID";
              SqlParameter[] sqlParameters = new SqlParameter[1];
              sqlParameters[0] = new SqlParameter("@AREAID", SqlDbType.VarChar);
              sqlParameters[0].Value = Convert.ToString(ent.AREAID);
              return conn.executeDeleteQuery(query, sqlParameters);
          }

    }
}
